package com.newbe.controller;

import com.newbe.entity.User;
import com.newbe.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Optional;

/**
 * @Auther: Newbe
 * @Date: 2019/9/24 23:58
 * @Description:
 */
@Api(value="用户接口",description = "用户信息接口")
@RestController
public class UserController {

    @Autowired
    private UserService userService;
    @ApiOperation(value="根据id获取用户信息",notes="方法备注说明")
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "id", value = "编号", required = true) })
    @RequestMapping(value = "/findUserById", method=RequestMethod.GET )
    public Optional<User> getUserById(int id){
        return userService.getUserById(id);
    }
    @ApiOperation(value="查询所有用户信息",notes="方法备注说明")
    @RequestMapping(value = "/findAll", method=RequestMethod.GET  )
    public List<User> findUserAll(){
        return userService.getUserAll();
    }


    @ApiOperation(value="根据id删除用户信息",notes="方法备注说明")
    @RequestMapping(value ="/del", method=RequestMethod.GET)
    public void del(int id){
        userService.del(id);
    }


    @ApiOperation(value="保存用户信息",notes="方法备注说明")
    @RequestMapping(value ="/save",method=RequestMethod.GET)
    public User save(User user){
        return userService.save(user);
    }

}
